home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / print.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.7 KB  |  99 lines

  1. ;void  print(strg);
  2. ;  char  *strg;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _time_out:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME  CS:_TEXT
  10.     PUBLIC  _print
  11. _print    proc near
  12.     jmp  short start    ;jmp over local data
  13. delay    dw   ?            ;
  14. target  dw   ?            ;
  15. start:    push bp            ;
  16.     mov  bp,sp        ;set stack frame
  17.     push si            ;
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    push ds            ;save DS
  23.     mov  ah,1        ;BIOS func to init prtr
  24.     mov  dx,0        ;choose LPT1
  25.     int  17h        ;initialize the prtr port
  26.     sub  ax,ax        ;clear AX
  27.     mov  es,ax        ;pt ES to 0000:0000
  28.     mov  dx,es:[408H]    ;get LPT1 base address
  29.     cmp  _memory_model,2    ;data near or far?
  30.     jb   L0            ;jump if near
  31.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  32.     jmp  short L00        ;
  33. L0:    mov  si,[bp+4]        ;near case
  34. L00:    mov  al,_time_out    ;get _time_out seconds
  35.     or   al,al        ;don't allow zero seconds
  36.     jnz  L1            ;
  37.     mov  al,3        ;default to 3 seconds
  38. L1:    mov  cl,18        ;18 ticks per second
  39.     mul  cl            ;
  40.     mov  cs:delay,ax    ;save count
  41.     cmp  byte ptr[si],0    ;test for null string
  42.     je   L4            ;quit if null
  43. L2:    mov  al,[si]        ;mov character to AL
  44.     inc  si            ;forward ptr for next time
  45.     cmp  al,0        ;end of string?
  46.     je   L4            ;
  47.     out  dx,al        ;send to output data register
  48.     inc  dx            ;forward to status register
  49.     push cx            ;save string counter
  50.     call GetBiosCount    ;get timer reading
  51.     mov  bx,cx        ;make copy
  52.     add  cx,cs:delay    ;add delay count
  53.     cmp  bx,cx        ;if timer doesn't turn over...
  54.     jb   L3            ;go ahead
  55.     mov  cx,cs:delay    ;otherwise, extend delay
  56. L3:    mov  cs:target,cx    ;save target count on stack
  57. Wait:    in   al,dx        ;get status value
  58.     test al,8        ;test for printer error
  59.     jz   KN            ;
  60.     test al,80h        ;test for printer Ready
  61.     jnz  Ready        ;jump if ready
  62. KN:    call GetBiosCount    ;
  63.     cmp  cx,cs:target    ;compare to target
  64.     jb   Wait        ;    
  65.     mov  bl,1        ;1 = error
  66.     pop  cx            ;restore string counter
  67.     jmp  short L5        ;go quit routine
  68. Ready:    pop  cx            ;restore string counter
  69.     inc  dx            ; output control register
  70.     mov  al,13        ;bits for strobe signal
  71.     out  dx,al        ;send the signal
  72.     dec  al            ;change to strobe OFF
  73.     out  dx,al        ;send the signal
  74.     dec  dx            ;point back to
  75.     dec  dx            ;  base address
  76.     jmp  short L2        ;loop
  77. L4:    mov  bl,0        ;0 = no error
  78. L5:    pop  ds            ;restore DS
  79.     mov  _error_code,bl    ;set _error_code
  80.     pop  si            ;
  81.     pop  bp            ;
  82.     cmp  _memory_model,0    ;quit
  83.     jle  quit        ;
  84.     db   0CBh        ;RET far
  85. quit:    ret            ;RET near
  86. GetBIOSCount PROC
  87.     push dx            ;return value in CX:DX
  88.     push ax            ;
  89.     sub  ah,ah        ;function number
  90.     int  1ah        ;get timer count
  91.     mov  cx,dx        ;low word in CX
  92.     pop  ax            ;
  93.     pop  dx            ;
  94.     ret
  95. GetBIOSCount endp
  96. _print    endp
  97. _TEXT    ENDS
  98.     END
  99.